//
//  TVTableViewCell.m
//  ITHome
//
//  Created by lanou3g on 15/7/16.
//  Copyright (c) 2015年 YAX. All rights reserved.
//

#import "TVTableViewCell.h"
#import "TVViewModel.h"
#import "Reachability.h"

@implementation TVTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


#pragma mark - 自定义cell初始化
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        // cell背景图
        self.cellBackgroundImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, kScreenWidth - 20, 220)];
      //  self.cellBackgroundImageView.image = [UIImage imageNamed:@"video_recommend_cell_bg"];
        [self.contentView addSubview:_cellBackgroundImageView];
        
        // TV背景图
        self.TVBackgroundImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, _cellBackgroundImageView.width, 180)];
//        self.TVBackgroundImageView.backgroundColor = [UIColor blueColor];
       // self.TVBackgroundImageView.image = [UIImage imageNamed:@"video_recommend_cell_bg"];
        [self.cellBackgroundImageView addSubview:_TVBackgroundImageView];
//
       
        
        //播放按钮图标
        self.startPlayImageView = [[UIImageView alloc] initWithFrame:CGRectMake(_TVBackgroundImageView.width / 2 -30, _TVBackgroundImageView.height / 2 - 20, 60, 40)];
//        self.startPlayImageView.backgroundColor = [UIColor greenColor];
        self.startPlayImageView.contentMode = UIViewContentModeCenter;
        self.startPlayImageView.image = [UIImage imageNamed:@"video_list_cell_big_icon"];
//        self.startPlayImageView.alpha = 0.5;
        [self.TVBackgroundImageView addSubview:_startPlayImageView];
        
        // 标题背景
        CGFloat titleImageViewY = _startPlayImageView.height + _startPlayImageView.y + 10;
        CGFloat titleImageViewHeight = _TVBackgroundImageView.height - (_startPlayImageView.height + _startPlayImageView.y + 10);
        self.titleImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, titleImageViewY, _TVBackgroundImageView.width, titleImageViewHeight)];
        self.titleImageView.backgroundColor = [UIColor blackColor];
        self.titleImageView.alpha = 0.5;
        [self.TVBackgroundImageView addSubview:_titleImageView];
        
        //视频标题
        CGFloat titleLabelY = _startPlayImageView.y + _startPlayImageView.height + 10;
        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, titleLabelY, _TVBackgroundImageView.width - 20, _titleImageView.height)];
//        self.titleLabel.backgroundColor = [UIColor orangeColor];
        self.titleLabel.textColor = [UIColor whiteColor];
        self.titleLabel.numberOfLines = 0;
        self.titleLabel.font = [UIFont systemFontOfSize:15];
        [self.TVBackgroundImageView addSubview:_titleLabel];
        
        // 时间图标
        self.timeIconImagevIew = [[UIImageView alloc] initWithFrame:CGRectMake(10, _TVBackgroundImageView.y + _TVBackgroundImageView.height + 10, 15, 15)];
//        self.timeIconImagevIew.backgroundColor = [UIColor orangeColor];
        self.timeIconImagevIew.image = [UIImage imageNamed:@"video_list_cell_time"];
        [self.cellBackgroundImageView addSubview:_timeIconImagevIew];
        
        // 时间
        self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(_timeIconImagevIew.x + _timeIconImagevIew.width + 10, _timeIconImagevIew.y, 100, _timeIconImagevIew.height)];
//        self.timeLabel.backgroundColor = [UIColor brownColor];
        self.timeLabel.font = [UIFont systemFontOfSize:13];
        self.timeLabel.textColor = [UIColor grayColor];
        [self.cellBackgroundImageView addSubview:_timeLabel];
        
    }
    return self;
}

#pragma mark - 加载数据
- (void)loadCellWithDataModel:(TVViewModel *)tvViewModel
{
    [self.TVBackgroundImageView sd_setImageWithURL:[NSURL URLWithString:tvViewModel.feature_img] placeholderImage:[UIImage imageNamed:@"video_recommend_cell_bg"]];
    self.titleLabel.text = tvViewModel.title;
    self.timeLabel.text = tvViewModel.video_length;
}


@end
